package com.ximu.user.handler;

import com.alibaba.fastjson.JSON;
import com.ximu.common_utlis.result.Result;
import com.ximu.common_utlis.result.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @projectName: graduation
 * @package: com.ximu.service_ucenter.handler
 * @className: AccessDeniedHandlerImpl
 * @author: ximu
 * @description: null
 * @date: 2022/5/28 14:48
 * @version: 1.0
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {

        Result result = Result.error2().data("error",HttpStatus.FORBIDDEN.value()).message("权限不足");
        String json = JSON.toJSONString(result);
        WebUtils.renderString(response,json);

    }
}
